import Demo.User;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Admin
 * Date: 2023-02-05
 * Time: 11:33
 */
public class App {
    public static void main(String[] args) {
        //1.获取Spring的上下文对象
        ApplicationContext context = new ClassPathXmlApplicationContext("spring-config.xml");

        //2.从Spring上下文对象中取出Bean对象(传统方式,在spring当中不推荐)
        //User user = new User();

        //2.1从Spring上下文对象中取出Bean对象(通过注册id获取spring当中的对象)
        //User user = (User) context.getBean("user");

        //2.2从Spring上下文对象中取出Bean对象(通过Class对象[类型]获取spring当中对象)
        //注意:这种方式是有风险的,当同一个类型注册到spring多次的时候,就会报错
        //User user = context.getBean(User.class);

        //2.3从Spring上下文对象中取出Bean对象(通过注册id + Class对象获取获取spring当中的对象)
        //这种方式就可以解决上方同一个类型注册多次的情况.
        User user = context.getBean("user",User.class);

        //3.使用Bean对象
        user.sayHi();
    }
}
